package com.heihei.service.impl;

import com.heihei.domain.SiteType;
import com.heihei.domain.SiteTypeExample;
import com.heihei.domain.User;
import com.heihei.mapper.SiteTypeMapper;
import com.heihei.service.SiteTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class SiteTypeServiceImpl implements SiteTypeService {
    @Autowired
    private SiteTypeMapper siteTypeMapper;

    @Override
    public List<SiteType> selectAllTypes(User currentUser) {
        SiteTypeExample example = new SiteTypeExample();

        //看当前登录用户是否有权限查看  特殊分类。根据权限决定是否显示特殊分类
        if(currentUser == null || (currentUser.getAuthority() != 1 && currentUser.getAuthority() != 2)) {
            example.createCriteria().andSecretEqualTo(0);
        }

        example.setOrderByClause("CONVERT(type USING gbk)");
        return siteTypeMapper.selectByExample(example);
    }
}
